
/*  
 * Error handling routines borrowed (lifted) from Stevens, Appendix A.3 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <syslog.h>
#include "tp_debug.h"


#ifndef CLIENT
#ifndef SERVER
#define CLIENT 1    /* default is client */
#endif /* SERVER */
#endif /* CLIENT */


char *pname = NULL;

void my_perror ();

#ifdef CLIENT      /* output to stderr */


/*
 * Recoverable error.  Print a message, and retun to caller.
 *
 *  err_ret(str, arg1, arg2, ...)
 *
 * The string "str" must specify the conversion for any args.
 *
 */

/*
 * Print UNIX errno value.
 *
 */
void my_perror ()
{
  char *sys_err_str ();

  fprintf (stderr, " %s\n", sys_err_str ());
}

#endif /*CLIENT */

#ifdef SERVER

/* We'll do this later. */

#endif /* SERVER */

#if !defined(errno)
extern int errno;
extern int sys_nerr;    /* # of error message strings in sys table */
#endif /* !defined(errno) */

/*
 * Portability Note:
 *  
 * sys_errlist is a portability thorn...
 *   
 * If you're compilation bombs due to it being undefined (or redefined)
 * in errors.c, this is the place to fix it. Older Linux systems (libc5.x)
 * will need to invert the logic of the below, to read
 *   extern const char *const sys_errlist[];
 *  
 * With other platforms, your milage may vary - sorry!
 *
 */

char *sys_err_str (void)
{
  return (strerror (errno));
}

void err_dump (char *text)

{
  LOG ("Gateway: %s\n", text);
  abort ();
  exit (1);
}


/* int h_errno; */      /* host error number */
int h_nerr;      /* number of error message strings */

